unit uFrameClassif;

{$mode objfpc}
{.$modeswitch typehelpers}
{.$modeswitch advancedrecords}
{$H+}
{$i orcis.inc}

interface

uses
    Classes, VirtualTrees, Forms, Controls, ComCtrls, ExtCtrls, Graphics,
    StdCtrls, types,
    uTypes, uInterfaces,
    BGRABitmap, BGRABitmapTypes;

type

    { TFraClassif }

    // Base class for hierarchical folder structures
    TFraClassif = class(TFrame, IISPanel)
        Button1: TButton;
        Panel1: TPanel;
        vtrMain: TVirtualDrawTree;
        procedure Button1Click(Sender: TObject);
        procedure vtrMainGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: integer);
        procedure vtrMainDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
    private
        FRootName: string;
        procedure SetRootName(AValue: string);
    protected
        function AddNode(AData: PClassifItemRec): PClassifItemRec; overload;
        function AddNode(const AID, AParent: string): PClassifItemRec; overload;
        procedure LoadData; virtual;

        function NodeByID(const AID: string): PVirtualNode;

        procedure AddVirtualNodes(const aAll: boolean = True); virtual;
    public
        // IISPanel
        // =================================================
        function GetCode: string; virtual;
        function GetCaption: string; virtual;
        function GetPanel: TWinControl; virtual;
        function GetFrame: TWinControl; virtual;

        procedure EmbedInto(aSurface: TWinControl); virtual;
    public
        // Name for the root element (if any) for other elements with emty parent
        // If emty then no root element will be shown
        property RootName: string read FRootName write SetRootName;
    end;

{ TRectHelper }
{
    TRectHelper = record helper for TRect
        function Width: Integer; inline;
        function Height: Integer; inline;

        procedure Init(const aLeft, aTop, aRight, aBottom: Integer); inline;

        procedure Move(const aDeltaX, aDeltaY: Integer); inline;
        procedure CenterIn(const aRect: TRect); inline;
    end;
}

implementation

{$R *.lfm}

{ TRectHelper }
{
function TRectHelper.Width: Integer;
begin
    Result := Right - Left;
end;

function TRectHelper.Height: Integer;
begin
    Result := Bottom - Top;
end;

procedure TRectHelper.Init(const aLeft, aTop, aRight, aBottom: Integer);
begin
    Left := aLeft;
    Top := aTop;
    Right := aRight;
    Bottom := aBottom;
end;

procedure TRectHelper.Move(const aDeltaX, aDeltaY: Integer);
begin
    Left := Left + aDeltaX;
    Right := Right + aDeltaX;
    Top := Top + aDeltaY;
    Bottom := Bottom + aDeltaY;
end;

procedure TRectHelper.CenterIn(const aRect: TRect);
begin

end;
}
{ TFraClassif }

procedure TFraClassif.vtrMainDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo);
var
    b: TBGRABitmap;
    d: PClassifItemRec;
    n: TClassifItem;
    rNode, rIcon, rText, rInfo: TRect;
begin
    rNode := PaintInfo.CellRect;
    //rNode.Move(-rNode.Width, -rNode.Height);

    //b := TBGRABitmap.Create(rNode.Width, rNode.Height, clWhite);
    try
        d := vtrMain.GetNodeData(PaintInfo.Node);
        n := d^.Data;
        // Background
        // =================================================

        // Icon
        // =================================================

        // Text
        // =================================================
        b.TextRect(rText, n.Caption, taLeftJustify, tlCenter, BGRABlack);

        // Info
        // =================================================

        // Draw
        // =================================================
    finally
        b.Free;
    end;
end;

procedure TFraClassif.Button1Click(Sender: TObject);
begin
end;

procedure TFraClassif.vtrMainGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: integer);
begin
    NodeDataSize := SizeOf(TClassifItemRec);
end;

procedure TFraClassif.SetRootName(AValue: string);
begin
    if FRootName = AValue then
        Exit;
    FRootName := AValue;
end;

function TFraClassif.AddNode(AData: PClassifItemRec): PClassifItemRec;
begin
end;

function TFraClassif.AddNode(const AID, AParent: string): PClassifItemRec;
begin
end;

procedure TFraClassif.LoadData;
begin

end;

function TFraClassif.NodeByID(const AID: string): PVirtualNode;
begin
    Result := nil;
    if AID = '' then
        Exit;
end;

procedure TFraClassif.AddVirtualNodes(const aAll: boolean);
begin

end;

function TFraClassif.GetCode: string;
begin
    Result := 'test';
end;

function TFraClassif.GetCaption: string;
begin
    Result := 'Test panel';
end;

function TFraClassif.GetPanel: TWinControl;
begin
    Result := Self;
end;

function TFraClassif.GetFrame: TWinControl;
begin
    Result := nil;
end;

procedure TFraClassif.EmbedInto(aSurface: TWinControl);
begin
    Self.Parent := aSurface;
    Self.Align := alClient;
    Self.Show;
    Self.BringToFront;
end;

end.
